#include "newQLable.h"


QPoint NewQLabel::curPos;

NewQLabel::NewQLabel(QWidget * parent)
{
    // QLabel::mouseDoubleClickEvent
}

NewQLabel::~NewQLabel()
{

}

void NewQLabel::mousePressEvent(QMouseEvent * event)
{
    float scalar = m_isFullScreen ? 1.0 / SCALARMAX : 1.0 / slt(easyWebServer::Json)["ImgSizeScalar"].asDouble();
    if(m_mat == nullptr) return;
    int data;
    if(m_mat->dataLength == 2)
    {
        data = m_mat->get<uint16_t>(event->pos().y() * scalar, event->pos().x() * scalar);
    }
    else if(m_mat->dataLength == 1)
    {
        data = m_mat->get<uint8_t>(event->pos().y() * scalar, event->pos().x() * scalar);
    }
    // QPoint curpos(this->pos().x() + event->pos().x() , this->pos().y() + event->pos().y());
    QToolTip::showText(event->globalPos(), QString().setNum(data), nullptr);
    // qDebug() << event->pos();
    // qDebug() << event->globalPos();
    // m_mat = nullptr;
    curPos.setX(event->pos().x() * scalar);
    curPos.setY(event->pos().y() * scalar);
}

// void NewQLabel::mouseMoveEvent(QMouseEvent * event)
// {
    // float scalar = m_isFullScreen ? 1.0 / SCALARMAX : 1.0 / SCALAR;
    // if(m_mat == nullptr) return;
    // int data;
    // if(m_mat->dataLength == 2)
    // {
    //     data = m_mat->get<uint16_t>(event->pos().y() * scalar, event->pos().x() * scalar);
    // }
    // else if(m_mat->dataLength == 1)
    // {
    //     data = m_mat->get<uint8_t>(event->pos().y() * scalar, event->pos().x() * scalar);
    // }
    // // QPoint curpos(this->pos().x() + event->pos().x() , this->pos().y() + event->pos().y());
    // QToolTip::showText(event->globalPos(), QString().setNum(data), nullptr);
    // qDebug() << event->pos();
    // qDebug() << event->globalPos();
    // m_mat = nullptr;
// }

void NewQLabel::mouseDoubleClickEvent(QMouseEvent * event)
{
    m_cb();
}



